﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Empires.RAL.Access;
using Empires.CRL.DataContract;
using Empires.RAL.ORM.CompanyData;

namespace Empires.RAL.Pump
{
    public class CompanyNoticeDataPump : ICompanyNoticeAccess
    {
        public List<DefaultDataPack> GetNoticeList(string copName, int type, int page, int size)
        {
            using (mysql_companyEntities ctx = new mysql_companyEntities())
            {
                var result = (from c in ctx.tb_notice
                              where c.c_vc_cpname == copName && c.c_i_type == type && !c.c_b_isdelete
                              orderby c.c_i_id descending
                              select new { c.c_nvc_title, c.c_i_id, c.c_dt_pbdate })
                              .Skip(page * size).Take(size)
                              .ToList()
                              .Select(c => new DefaultDataPack()
                              {
                                  TITLE = c.c_nvc_title,
                                  ID = c.c_i_id,
                                  DATE = c.c_dt_pbdate.ToString("yyyy-MM-dd")
                              }).ToList();
                return result;
            }
        }


        public List<DefaultDataPack> GetNoticeArticle(string copName, int nid)
        {
            using (mysql_companyEntities ctx = new mysql_companyEntities())
            {
                var result = (from c in ctx.tb_notice
                              where c.c_vc_cpname == copName && c.c_i_id == nid && !c.c_b_isdelete
                              orderby c.c_i_id descending
                              select new { c.c_nvc_title, c.c_dt_pbdate,c.c_nvc_content })
                              .ToList()
                              .Select(c => new DefaultDataPack()
                              {
                                  TITLE = c.c_nvc_title,
                                  CONTENT = c.c_nvc_content,
                                  DATE = c.c_dt_pbdate.ToLongDateString()
                              }).ToList();
                return result;
            }
        }
    }
}
